<template>
	<view class="com-chat-middle">
		<!-- 10：固定的提示信息 -->
		<view class="tips-box box-set" v-if="msgItem.msn_type==19">
			<view class="tips-content con-set chat-bg">
				<view class="box-title">处方药复诊开方服务</view>
				<view class="con-options">
					<view class="opt-item" v-for="(item,index) in listData">
						<text class="hkfont hk-dunpai"></text>
						<view class="title">{{item}}</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 11：患者问诊信息 -->
		<view class="userinfo-box box-set" v-if="msgItem.msn_type==17">
			<view class="user-content con-set chat-bg">
				<view class="section-box">
					<view class="section">
						<text class="hkfont hk-jilu"></text>
						<view class="box-title">问诊信息</view>
					</view>
				</view>
				<view class="info-item">
					<view class="left">用户信息：</view>
					<view class="right">
						<text class="users">{{formatUser(msgItem)}}</text>
						<!-- <text class="desc">|</text>
						<text class="desc">{{formatDisease(msgItem)}}</text> -->
					</view>
				</view>
				<view class="item-line"></view>
				<view class="list-item" v-for="(listItem,index) in msgItem.products">
					<view class="info-item">
						<view class="left">病情描述：</view>
						<view class="right">{{formatSymptom(listItem,msgItem)}}</view>
					</view>
					<view class="info-item">
						<view class="left">药品需求：</view>
						<view class="right">{{formatProduct(listItem)}}</view>
					</view>
				</view>
				<view class="notice">
					<text class="iconfont icon-zhuyi-copy">确认已在线下就诊，使用过所购买药品且无过敏或不良反应，当前病情稳定</text>
				</view>
			</view>
		</view>

		<!-- 12：处方信息 -->
		<view class="rp-box box-set" v-if="msgItem.msn_type==18">
			<view class="rp-content con-set chat-bg2">
				<view class="section-box">
					<view class="section">
						<text class="hkfont hk-chufang"></text>
						<view class="box-title">电子处方</view>
					</view>
					<view class="right" @click="clickRpItem(msgItem)">
						<view class="title">原始处方</view>
						<text class="iconfont icon-jiantou"></text>
					</view>
				</view>
				<view class="info-item">
					<view class="left">患者：</view>
					<view class="right">
						<text class="users">{{formatUser(msgItem)}}</text>
					</view>
				</view>
				<view class="info-item">
					<view class="left">诊断：</view>
					<view class="right">
						{{msgItem.diagnosis || ''}}
					</view>
				</view>
				<view class="info-item">
					<view class="left">开方时间：</view>
					<view class="right">
						{{msgItem.rp_time || ''}} 
					</view>
				</view>
			</view>
		</view>



	</view>
</template>

<script>
	
	export default {
		name: 'chat-middle',
		props: {
			msgItem: {
				type: Object,
				default: function() {
					return {}
				}
			},
			rp_status:{
				type:Number|String,
				default:0,
			},
			isDoctor:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				listData: ["100%医生资质审核", "处方安全保障", "平台双重质检"]
			}
		},
		methods: {
			// 用戶
			formatUser(item) {
				let user_str = '';
				if (item.inquiry) {
					let userInfo = item.inquiry;
					let userArray = [
						userInfo.patient_name,
						userInfo.patient_gender == 1 ? '男' : '女',
						userInfo.patient_age + '岁',
					];
					user_str = userArray.map(item => item).join(' ')
				}
				return user_str;
			},
			// 病史
			formatDisease(item) {
				let disease_str = '无疾病史/非妊娠哺育';
				if (item.inquiry.is_disease == 1) {
					disease_str = this.$util.symptomsToStr(item.inquiry.disease);
				}
				return disease_str;
			},
			// 症状
			formatSymptom(listItem, msgItem) {
				if(msgItem.symptom){
					let symptoms = msgItem.symptom;
					let values = symptoms[listItem.productid];
					let sym_str = values.map(item => item).join('；')
					return sym_str;
				}
				return'--';
			},
			// 药品
			formatProduct(listItem) {
				let name = listItem.name;
				if (listItem.unit_name) {
					name += '/' + listItem.unit_name;
				}
				name += ' x' + listItem.nums;
				return name;
			},
			
			clickRpItem(item) {
				// 0待开方  1待结算  2 已支付
				let that = this
				if(this.isDoctor){
					if(!item.rp_url || item.rp_url.length<=0){
						return this.$util.Tips({title:'处方获取失败'});
					}
					
					let pdf_rpurl = item.rp_url[0];
					let url = encodeURIComponent(JSON.stringify(pdf_rpurl));
					uni.navigateTo({
						url: "/pages/rp/rp_pdfs/rp_pdfs?move_url=" + url,
					})
				}else{
					console.log(item)
					if(item.ispay !=1){
						return this.$util.Tips({title:'处方信息需结算完成才可查看'});
					}
					
					if(!item.rp_url || item.rp_url.length<=0){
						return this.$util.Tips({title:'处方获取失败'});
					}
					
					let pdf_rpurl = item.rp_url[0];
					let url = encodeURIComponent(JSON.stringify(pdf_rpurl));
					uni.navigateTo({
						url: "/pages/rp/rp_pdfs/rp_pdfs?move_url=" + url,
					})	
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.com-chat-middle {
		width: 100%;
	}

	.box-set {
		background-color: #fff;
		border-radius: 10rpx;
	}
	.con-set {
		padding: 20rpx 20rpx;
	}
	.chat-bg {
		background: url('../static/rp_chat_bg.png') no-repeat;
		background-size: 100% auto;
	}
	.chat-bg2 {
		background: url('../static/rp_detail.png') no-repeat;
		background-size: 100% auto;
	}

	.box-title {
		font-weight: bold;
	}

	.tips-box {
		/* #ifdef MP-WEIXIN */
		width: 710rpx;
		/* #endif */
		.tips-content {

			.con-options {
				display: flex;
				flex-wrap: wrap;
				margin-top: 10rpx;

				.opt-item {
					margin-right: 20rpx;

					&:nth-last-child(1) {
						margin-right: 0rpx;
					}

					display: flex;
					align-items: center;
					font-size: 10px;
					color: #969696;

					.hkfont {
						font-size: 14px;
						color: #D27D55;
					}
				}
			}
		}

	}

	.info-item {
		display: flex;
		margin-top: 10rpx;

		.left {
			width: 150rpx;
			color: #969696;
		}

		.right {
			width: calc(100% - 150rpx);

			.users {}

			.desc {
				margin-left: 10rpx;
				color: #969696;
			}
		}
	}

	.section-box {
		display: flex;
		justify-content: space-between;
		margin: 10rpx 0 20rpx;

		.section {
			display: flex;
			align-items: center;

			.hkfont {
				margin-right: 5rpx;
				color: #EC3700;
			}

			.title {}
		}

		.right {
			display: flex;
			align-items: center;
			color: #D27D55;

			.iconfont {
				color: #D27D55;
			}
		}
	}

	.userinfo-box {
		.user-content {
			
			.list-item {
				padding-bottom: 10rpx;

				&:nth-last-child(1) {
					padding-bottom: 0rpx;
				}
			}

			.item-line {
				height: 1rpx;
				background-color: #ccc;
				margin: 20rpx 0rpx;
			}

			.notice {
				display: flex;
				margin-top: 10rpx;

				.iconfont {
					color: #969696;
					font-size: 14px;
				}

				.icon-zhuyi-copy::before {
					padding-right: 5rpx;
				}
			}
		}
	}

	.rp-box {
		/* #ifdef MP-WEIXIN */
		width: 710rpx;
		/* #endif */
		.rp-content {}
	}
</style>